<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>补卡列表</title>
  <link rel="stylesheet" href="../../../layui/css/layui.css">
  <script src="../../../layui/layui.js"></script>
</head>
<style type="text/css">
  body{
    height: 100%;
    width: 100%;
    margin-top: 11px;
  }


</style>

<body >
<!-- 内容主体区域 -->
<div class="layui-fluid layui-form">
  <div class="layui-form-item">
    <div class="layui-input-inline " style="/* width: 438px;*/">
      <button class="layui-btn layui-btn-primary apply">审核</button>
      <!--      <button class="layui-btn">默认按钮</button>
            <button class="layui-btn layui-btn-normal">百搭按钮</button>-->
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">搜索选择框</label>
      <div class="layui-input-inline">
        <select name="modules"  lay-search="" class="storeList"  lay-filter="storeid">
          <option value="stuff_name">员工名称</option>
          <option value="audit_statu">补卡状态</option>
        </select>
      </div>
    </div>
    <div class="layui-inline">
      <div class="layui-input-inline">
        <input type="text" name="userKey" class="layui-input value ">
      </div>
      <div class="layui-input-inline">
        <button class="layui-btn layuiadmin-btn-admin layui-btn-normal check" lay-submit="" lay-filter="LAY-user-back-search">
          <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
        </button></div>
    </div>
  </div>
</div>

<div id="pTable" >
  <table id="layui_table_id" class="layui-table" lay-skin="line" lay-filter="test" style="width: 1680px">

  </table>
  <!--  <script type="text/html" id="barDemo">
      <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
      <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>-->
  <div id="laypage"></div>
</div>
<input type="hidden" id="storeId" name="storeId " vlaue="" class="layui-input userKeyValue ">
</body>
</html>

<script type="text/javascript">
  layui.use(['form','laydate','layer','table','laypage','util'],function(){

    var form = layui.form;
    var laydate=layui.laydate;
    var $ = layui.$;
    productsearch(1);
   /* form.on('select(storeid)', function(data){
      console.log(data.value);
      $("#storeId").val(data.value);
      productsearch(1,"",data.value);
    })*/
    function productsearch(page,filterExpr,stuffName,storeId) {

      var table = layui.table,
              laydate = layui.laydate,
              laypage = layui.laypage;
      var form = layui.form;

      table.render({
        elem : '#layui_table_id',
        url : '/hy/basic/attendance/getPatchCardList',
        cols : [ [
          {checkbox: true,
            filter:'test'
          }
          ,
          {
            field : 'recordId',
            title : 'recordId',
            sort : true,
            align : 'center'
          }
          , {
            field : 'auditPerson',
            title : '员工名称',
            align : 'center'
          }
          , {
            field : 'reson',
            title : '补卡原因',
            align : 'center',
          }
          , {
            field : 'retroactiveType',
            title : '补卡类型',
            align : 'center'
          }
          , {
            field : 'auditStatu',
            title : '补卡状态',
            align : 'center'
          }
          , {
            field : 'auditOpinion',
            title : '审核意见',
            align : 'center'
          }

        ] ],
        page : true,
        where : {
          filterExpr:filterExpr,
          storeId:storeId,
          stuffName:stuffName
        },
        responseHandler: function (res, curr,count) {
          $('#pageNum').val(curr);
          /*          console.log(res.listMap);
                    var listMap = res.listMap;
                    var chechId  = res.chechId;
                    if(listMap.length>0){
                      for(index in listMap){
                        if(index==0){
                          var temp = listMap[index].recordId;
                          $("#storeId").val(temp);
                        }
                        var temp = "";
                        if(chechId==listMap[index].recordId){
                          temp = "<option selected='selected' value="+listMap[index].recordId+">"+listMap[index].salonName+"</option>";
                        }else{
                          temp = "<option value="+listMap[index].recordId+">"+listMap[index].salonName+"</option>";
                        }

                        $(".storeList").append(temp);
                        form.render();//表单重新渲染，要不然添加完显示不出来新的option
                      }
                    }*/

          return {
            "count": res.total,
            "data": res.data,
            "code": 0,//code值为200表示成功
            "msg": ""
          }
        },
        done : function(res, curr, count) {
          console.log(res)
          $('#pageNum').val(curr);

        }
      })
      // table.on('checkbox(test)', function(obj){
      //   console.log(layui.table.checkStatus('layui_table_id'));
      // });
      // 监听工具条
      table.on('tool(test)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
        var data = obj.data, //获得当前行数据
                layEvent = obj.event; //获得 lay-event 对应的值
        if (layEvent == 'detail') {
          queryById(data.id);
        } else if (layEvent == 'del') {
          //alert(data.id)
          var pageNum = $('#pageNum').val();
          layer.confirm('真的删除行么', function(index){
            deleteById(data.id);
            layer.close(index);
            //向服务端发送删除指令
          });
        } else if (layEvent === 'edit') {
          layer.msg('编辑操作');
        }
      });
      //常规用法
      laydate.render({
        elem : '#createDate'
      });
      //常规用法
      laydate.render({
        elem : '#processingTime'
      });

    }

    $(".check").on("click", function() {

      var key=$('.storeList option:selected').val();
      if(key!=""){
        var value = $('.value').val();
        var stuffName = "";
        var temp ="";
        if(key=='stuff_name'){
          stuffName = value;
        }else{
          temp =  key+"='"+value+"'";
        }

        if(key=="audit_statu"){
          if(value=="通过"){
            temp =  key+"="+0+"";
          }else{
            temp =  key+"="+1+"";
          }

        }


        productsearch(1, temp ,stuffName);
      }else{
        productsearch(1);
      }

    })

    $(".apply").on("click",function(){
      var data = layui.table.checkStatus('layui_table_id').data;
      if(data.length<1){
        alert("请选中一条数据");
        return false;
      }
      layer.open({
        type:2,
        area:[450+'px',239+'px'],
        fix:false,
        offset: '80px',
        maxmin:true,
        shadeClose:true,
        scrollbar: false,
        shade:0.4,
        title:'审核意见',
        content:['patch_card_apply.html'],
        success:function(layero,index){
          var iframe = window['layui-layer-iframe' + index];
          // 向子页面的全局函数child传参
          iframe.child(data[0]);
          console.log("成功");
        },
        fail:function(data){
          console.log(data);
        }
      })
    })
  });
  function userStatus(t){
    if(t==0){
      return '启用';
    }else{
      return '禁用';
    }
    return util.toDateString(t1);
  }
</script>


<script type="text/html" id="userStatus">


  {{ userStatus(d.userStatus) }}
</script>